/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs425proj.model;


import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.text.SimpleDateFormat;

import java.util.Collections;

/**
 *
 * @author prateekpatil
 */
public class scheduleDetail {
    
    private int screen_id;
    private String timing;
    private Date startdate;
    private Date enddate;
    private int movie_id;
    
    public ArrayList<Long> getDateList(String movie)
    {
    
        ArrayList<Long> dateList = new ArrayList<Long>();
        ArrayList<Long> startList = new ArrayList<Long>();
        ArrayList<Long> endList = new ArrayList<Long>();
        ResultSet rs;
        try{
        connectDB obj = new connectDB();
        Statement stm;
        Date current = null;
        stm =  obj.startConnection().createStatement();
        String qry="select startdate, enddate from schedule where movie_id in (select movie_id from movie where name='"+movie+"')";
        rs = stm.executeQuery(qry);
        int i=0;
        while(rs.next()){
                startList.add(rs.getDate(1).getTime());
                endList.add(rs.getDate(2).getTime());
        }
        
        String qry1="Select SYSDATE from dual";
        rs = stm.executeQuery(qry1);
        while(rs.next())
        {
            current=rs.getDate(1);
        }
        
        Collections.sort(startList);
        Collections.sort(endList);
        int index = startList.size();
        
        long minStartDate = startList.get(0);
        long maxEndDate = endList.get((index-1));
        

//        java.sql.Date current = (java.sql.Date) currentDate.getTime();
         
        long dateInEpoch = current.getTime();
//         System.out.println("Our date"+dateInEpoch+" "+maxEndDate);       
        if(dateInEpoch>minStartDate)
        {
            //Display current to maxEndDate
            dateList.add(dateInEpoch);
            dateList.add(maxEndDate);           
        
        }else
        {       
            //Display minStartDate to maxEndDate
            dateList.add(minStartDate);
            dateList.add(maxEndDate);
        }
                
        
        
        obj.closeConnection();
        }catch(SQLException e){e.printStackTrace();}
        
        return dateList;
    }

    public Date getEnddate() {
        return enddate;
    }

    public void setEnddate(Date enddate) {
        this.enddate = enddate;
    }

    public int getMovie_id() {
        return movie_id;
    }

    public void setMovie_id(int movie_id) {
        this.movie_id = movie_id;
    }

    public int getScreen_id() {
        return screen_id;
    }

    public void setScreen_id(int screen_id) {
        this.screen_id = screen_id;
    }

    public Date getStartdate() {
        return startdate;
    }

    public void setStartdate(Date startdate) {
        this.startdate = startdate;
    }

    public String getTiming() {
        return timing;
    }

    public void setTiming(String timing) {
        this.timing = timing;
    }

    
    
}
